package cn.dgfy.ssm.util;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


public class DateTimeHelper {
	
	private static DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	public static Date getDateFromString(String date) {
		if (date == null || "".equals(date.trim())) {
			return null;
		}
		
		try {
			return sdf.parse(date.trim());
		} catch(ParseException e) {
			return null;
		}
	}
	
	public static String getStringFromDate(Date date) {
		if (date == null) {
			return null;
		} else {
			return sdf.format(date);
		}
	}
	
	public static Date getDateFromTimestamp(Timestamp timestamp) {
		if (timestamp == null) {
			return null;
		} else {
			return new Date(timestamp.getTime());
		}
	}
	
	public static Timestamp getTimestampFromDate(Date date) {
		if (date == null) {
			return null;
		} else {
			return new Timestamp(date.getTime());
		}
	}
}
